<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Jedrzej\Pimpable\PimpableTrait;

class SystemLog extends Model
{
    use HasFactory;
    use PimpableTrait;

    public $searchable = [
        'admin_id',
        'path',
        'admin_name',
        'merchant_id',
        'method',
        'ip',
        'type',
        'path',
    ];

    /**
     * 设置模糊搜索
     */
    public $searchableModels = [
        'admin_name' => '%field%',
        'ip' => '%field%',
    ];

    public $fillable = [
        'admin_id',
        'admin_name',
        'merchant_id',
        'path',
        'action',
        'method',
        'type',
        'ip'
    ];

    public $sortable = [
        'admin_id',
        'merchant_id',
    ];

    protected $defaultSortCriteria = ['id,desc'];

    /**
     * 组合数据详情所属数据组
     */
    public function systemAdmin()
    {
        return $this->belongsTo(SystemAdmin::class, 'admin_id','id');
    }

    /**
     * 组合数据详情所属数据组
     */
    public function merchantRegister()
    {
        return $this->belongsTo(MerchantRegister::class, 'merchant_id','id');
    }
}
